package pers.gxm.singleton;

public class Triple {
    public static void main(String[] args) {
        Triple i0 = Triple.getInstance(0);
        Triple i1 = Triple.getInstance(1);
        Triple i2 = Triple.getInstance(2);

        System.out.println("====");
        Triple i22 = Triple.getInstance(2);
        System.out.println(i2==i22);

    }
    private static Triple[] triples = new Triple[3];
    private int id;
    private Triple(int id){
        this.id = id;
    }
    public int getId(){
        return id;
    }
    private static Triple getInstance(int id){
        if(triples[id] == null){
            System.out.printf("创建id为:%d的实例\n",id);
            triples[id] = new Triple(id);
        }
        return triples[id];
    }
}
